<template>
  <div class="total-container">
    <div class="top-container">
      <div class="item-box" v-for="item in topData" :key="item.name">
        <div class="title">{{ item.name }}</div>
        <div class="value">
          <div class="num">
            <countTo :startVal="0" :endVal="item.num" :duration="1200" separator=""></countTo>
          </div>
          <div class="unit">{{ item.unit }}</div>
        </div>
      </div>
    </div>
    <div v-if="!!bottomData.xAxis.data.length" class="bottom-container">
      <doubleBarLine :chart-data="bottomData"></doubleBarLine>
    </div>
  </div>
</template>
<script>
import doubleBarLine from '../charts/doubleBarLine.vue'
import countTo from 'vue-count-to'
import { rkqk } from '@/api/dongyingData'
export default {
  data() {
    return {
      topData: [
        {
          name: '常住人口',
          num: 0,
          unit: '万人'
        },
        {
          name: '城镇化率',
          num: 0,
          unit: '%'
        }
      ],
      bottomData: {
        xAxis: { name: '', data: [] },
        yAxis1: { name: '单位：万人', data: [] },
        yAxis2: { name: '单位：%', data: [] },
        data1: {
          name: '常住人口',
          data: [],
          unit: '万人'
        },
        data2: {
          name: '城镇人口',
          data: [],
          unit: '万人'
        },
        data3: {
          name: '城镇化率',
          data: [],
          unit: '%'
        }
      }
    }
  },
  components: {
    doubleBarLine,
    countTo
  },
  mounted() {
    this.getData()
  },
  methods: {
    async getData() {
      const [res1, res2] = await Promise.all([rkqk.data1(), rkqk.data2()])
      this.topData[0].num = res1.result[0].live_people
      this.topData[1].num = res1.result[0].czhl
      res2.result.forEach(element => {
        this.bottomData.xAxis.data.push(element.sj)
        this.bottomData.data1.data.push(+element.live_people)
        this.bottomData.data2.data.push(+element.city_people)
        this.bottomData.data3.data.push(+element.czhl)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.total-container {
  .top-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    .item-box {
      height: 46px;
      width: 206px;
      background: url('../../img/left-row2-icon1.png') no-repeat center center;
      background-size: 100% 100%;
      display: flex;
      justify-content: space-around;
      align-items: baseline;
      .title {
        font-family: MicrosoftYaHeiUI;
        font-size: 16px;
        color: #ffffff;
        line-height: 16px;
        text-shadow: 2px 0px 218px #029c99;
        text-align: center;
        font-style: normal;
        text-transform: none;
      }
      .value {
        display: flex;
        justify-content: end;
        align-items: baseline;
      }
      .num {
        font-family: MicrosoftYaHeiUI, MicrosoftYaHeiUI;
        font-weight: bold;
        font-size: 20px;
        color: #ffde00;
        line-height: 20px;
        text-shadow: 4px 0px 2px #024181;
        text-align: center;
        font-style: normal;
        text-transform: none;
      }
      .unit {
        font-family: MicrosoftYaHeiUI;
        font-size: 14px;
        color: #feffff;
        line-height: 14px;
        text-align: center;
        font-style: normal;
        text-transform: none;
        margin-left: 3px;
      }
    }
  }
  .bottom-container {
    height: 200px;
  }
}
</style>
